﻿using GeneralDutyRoomSystem.Models;
using Microsoft.AspNetCore.Mvc;

namespace GeneralDutyRoomSystem.Controllers
{
    //待收案件<已保存待立案案件>
    public class savesuccessController : Controller
    {
        private readonly SqlSugar.ISqlSugarClient db;
        public savesuccessController(SqlSugar.ISqlSugarClient _db)
        {
            this.db = _db;
        }
        public IActionResult Index()
        {
            return View();
        }
        //点击进入详情页面
        public IActionResult detail()
        {
            return View();
        }
        //双表查询basicinformationtable和caseclassificationtable
        public IActionResult getDepartInfo(int page, int limit, string strName)
        {
            int total = 0;
            var query = db.Queryable<basicinformationtable>()
                .LeftJoin<caseclassificationtable>((a,b)=>a.ClassificationId==b.ClassificationId)
                .Where(a => (string.IsNullOrEmpty(strName) || a.CallerName.Contains(strName)))
                .Select((a, b) => new { a.CaseDocument, b.CaseLevel, a.DataSources, a.EventType, b.CaseTypeName, a.Sendtime })
                .ToPageList(page, limit, ref total);

            var json = new
            {
                code = 0,
                data = query,
                count = total,
                msg = ""
            };
            return Json(json);
        }
        [HttpPost]
        //新建案件
        public IActionResult Add(basicinformationtable basic)
        {
            var result = db.Insertable(basic).ExecuteCommand();
            return Json(result);
        }
    }
}
